



cap program drop coefsv
do "${code}/0.Programs/coefsv.do"
gl out "${output}/seasonality"
gl outmain "${output}/forPaper"

graph drop _all

/*------------------------------------------------------------------------------
				1. KENYA GE
------------------------------------------------------------------------------*/
gl grset graphregion(color(white)) ylabel(, angle(0)) plotregion(margin(sides))
gl covid = mdy(3,23,2020)


qui do "${code}/Data Preparation/dataprep_kenya_ge"
sum ___depression_nw if date < mdy(3,1,2020)
replace ___depression_nw = ___depression_nw - `r(mean)'

if 1 == 1{
append using "${raw}/kenya_ge/kenya_ge_seas", gen(seas_added)
*bysort seas_added (day): replace date = mdy(12,31,2019) + _n if seas_added == 1
*replace date = date - 365 if seas_added == 1 & date > mdy(10,1,2020)
*replace _ctrl_seas = -1*_ctrl_seas
sum _ctrl_seas if date < mdy(2,1,2020)
replace date = date - 20 if seas_added == 1
replace _ctrl_seas = (_ctrl_seas - `r(mean)')/`r(sd)'/12 + .02
keep if month != 52
loc y ___depression_nw
areg `y' ib1.month, absorb(pid) vce(cluster hhid)
	coefsv `y' month
	cap drop *_`y' `y'_lo `y'_hi `y'1
	ren (r1 b1 b_lo b_hi) (Round_`y' `y'1 `y'_lo `y'_hi) 
	loc cis rcap `y'_lo `y'_hi Round_`y' 
	loc plot (scatter `y'1 Round_`y' if Round_`y' < mdy(1,1,2018),  mlwidth(0) col(maroon)) ///
			(`cis' if Round_`y' < mdy(1,1,2018), col(maroon) msize(vtiny))
	tw (line _ctrl_seas date if originalSamp == 1 & date > mdy(3,1,2016) , sort) ///
	 (line _ctrl_seas date if date < mdy(1,1,2018) & date > mdy(4,1,2017), sort lpattern(dash) col(gs5)) ///
	  `plot' , xline($covid, lpattern(dash))  fxsize(100) ytitle(Standard Deviation Units) /// 
		xlabel( , format(%tdmy)) $grset  name(first, replace) ///
		legend(order(1 "Seasonal Food Security, Original Data" ///
				2 "Seasonal Food Security, Predicted" 3 "Mental Health" ) rows(3))   //
		
		tw (scatteri 0.3 1 0.3 2 -0.3 2 -0.3 1, recast(area) fcolor(gs10%1) lcolor(gs10%1)),  ///
			xline( 1(0.1)1.8 , lpattern(".") lcolor(gs10)) ///
			xline( 1(0.2)1.8 , lcolor(gs10)) ///
			graphregion(color(white)) fxsize(0.5) name(cut, replace) yscale(off) xtitle("") xlabel(none)
				
		loc plot (scatter `y'1 Round_`y' if Round_`y' > mdy(1,1,2018),  mlwidth(0) col(maroon)) ///
			(`cis' if Round_`y' > mdy(1,1,2018), col(maroon) msize(vtiny))
	tw  (line _ctrl_seas date if date > mdy(10,1,2019) & date < mdy(10,1,2020), sort lpattern(dash) col(gs5)) ///
	  `plot' , xline($covid, lpattern(dash))  fxsize(57.1)  /// 
		xlabel( , format(%tdmy)) $grset name(second, replace) yscale(off) xtitle("") ///
		legend(order(1 "Seasonal Food Security, Original Data" ///
				2 "Seasonal Food Security, Predicted" 3 "Mental Health" ) rows(3))   //
				
	grc1leg first cut second, cols(3)  graphregion(color(white)) imargin(medsmall) ///
		ycommon name(ken) saving("${out}\ken2.gph", replace) title(B. KEN2)
	graph export "${out}/eventSeas_kenya_ge.png", replace
}


/*------------------------------------------------------------------------------
				2. NEPAL
------------------------------------------------------------------------------*/

qui do "${code}/Data Preparation/dataprep_nepal"
gl out "${output}/seasonality"

cap program drop coefsv
do "${code}/0.Programs/coefsv.do"

gl grset graphregion(color(white)) ylabel(, angle(0)) plotregion(margin(sides))
gl covid = mdy(3,23,2020)


gen postCat = (date > mdy(3,23,2020)) + (date > mdy(5,23,2020)) + (date > mdy(7,23,2020)) ///
	+ (date > mdy(9,23,2020)) + (date > mdy(12,23,2020)) + (date > mdy(3,23,2021)) if !mi(date)
label define postCat 1 "0-2 months" 2 "2-4 months" 3 "4-6 months" 4 "6-9 months" ///
	5 "9-12 months" 6 "12-15 months"
label values postCat postCat

*				0.1 Aggregate food security to analysis time periods
*-------------------------------------------------------------------------------
egen mseas = mean(_ctrl_seas), by(postCat)
gen ctrl_seasAg = mseas
replace ctrl_seasAg = _ctrl_seas if date < mdy(2, 1, 2020)


/*------------------------------------------------------------------------------
				1. Analysis
------------------------------------------------------------------------------*/

*				1.1 Plot FS with MH pre-COVID
*-------------------------------------------------------------------------------
append using "${raw}/nepal/nepal_seas", gen(seas_added)
bysort seas_added (day): replace date = mdy(12,31,2019) + _n if seas_added == 1
replace date = date - 365 if seas_added == 1 & date > mdy(10,1,2020)
replace _ctrl_seas = -1*_ctrl_seas
sum _ctrl_seas if date < mdy(2,1,2020)
replace _ctrl_seas = (_ctrl_seas - `r(mean)')/`r(sd)'/20 - 0.04
loc y ___depression_nw
areg `y' ib1.month, absorb(pid) vce(cluster hhid)
	coefsv `y' month
	cap drop *_`y' `y'_lo `y'_hi `y'1
	ren (r1 b1 b_lo b_hi) (Round_`y' `y'1 `y'_lo `y'_hi) 
	loc cis rcap `y'_lo `y'_hi Round_`y' 
	loc plot (scatter `y'1 Round_`y',  mlwidth(0)) (`cis' , col(maroon) msize(vtiny))
	tw (line _ctrl_seas date, sort) `plot' , xline($covid, lpattern(dash)) /// 
		xlabel( , format(%tdmy)) ytitle(Standard Deviation Units) $grset ///
		legend(order(1 "Seasonal Food Security"  2 "Mental Health" ))    ///
		name(npl) title(A. NPL)
	graph export "${out}/eventSeas_nepal.png", replace
	
	graph use "${out}\ken2.gph", name(ken2)
	graph combine npl ken2, xsize(8) graphregion(color(white))
		graph export "${outmain}/Fig1.png", replace

